package com.dandandog.framework.faces.exception;

import com.dandandog.framework.common.utils.MessageUtil;
import org.springframework.context.MessageSource;

import java.util.Locale;


public class MessageResolvableException extends RuntimeException {

    private final String errorCode;
    private final Object[] parameters;

    public MessageResolvableException(String errorCode) {
        this(errorCode, new Object[0], null);
    }

    public MessageResolvableException(String errorCode, Object[] parameters) {
        this(errorCode, parameters, null);
    }

    public MessageResolvableException(String errorCode, Throwable cause) {
        this(errorCode, null, cause);
    }

    public MessageResolvableException(String errorCode, Object[] parameters, Throwable cause) {
        super(cause);
        this.errorCode = errorCode;
        this.parameters = parameters;
    }

    public String getErrorCode() {
        return this.errorCode;
    }

    public Object[] getParameters() {
        return this.parameters;
    }

    public String getMessage(Locale locale) {
        return MessageUtil.getMessageSource(this.errorCode, locale, this.parameters);
    }
}
